package com.it.App.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: CaoYouGen
 * @DateTime: 2023/11/22/10:14
 * @注释: TODO
 **/
@RestController
@Api(tags = "测试专用接口")
public class TestController {

    @GetMapping("hello")
    @ApiOperation("测试接口hello")
    @PreAuthorize("hasAuthority('hello')")
    public String hello(){
        return "您请求了一个测试接口-hello";
    }

    @GetMapping("hello2")
    @ApiOperation("测试接口hello多个权限")
    @PreAuthorize("hasAnyAuthority('hello','sys:role:save')")
    public String hello2(){
        return "您请求了一个测试接口-hello多个权限";
    }

    @GetMapping("hello3")
    @ApiOperation("自定义权限校验")
    @PreAuthorize("@MyEx.hasAuthority('hello')") // 在SPEL表达式中使用@MyEx相当于获取容器中bean的名字未MyEx的对象。
    public String hello3(){
        return "您请求了一个测试接口-hello自定义权限校验";
    }
}












